home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / nfsmount / RCS / main.c,v < prev    next >
Text File  |  1991-10-20  |  10KB  |  493 lines

  1. head     1.11;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.11
  10. date     91.10.20.12.37.45;  author mottsmth;  state Exp;
  11. branches ;
  12. next     1.10;
  13.  
  14. 1.10
  15. date     91.03.23.18.34.06;  author mottsmth;  state Exp;
  16. branches ;
  17. next     1.9;
  18.  
  19. 1.9
  20. date     91.03.23.18.30.03;  author mottsmth;  state Exp;
  21. branches ;
  22. next     1.8;
  23.  
  24. 1.8
  25. date     91.03.23.18.24.45;  author mottsmth;  state Exp;
  26. branches ;
  27. next     1.7;
  28.  
  29. 1.7
  30. date     90.01.25.17.19.06;  author brent;  state Exp;
  31. branches ;
  32. next     1.6;
  33.  
  34. 1.6
  35. date     89.06.16.08.50.31;  author brent;  state Exp;
  36. branches ;
  37. next     1.5;
  38.  
  39. 1.5
  40. date     89.02.02.15.02.43;  author brent;  state Exp;
  41. branches ;
  42. next     1.4;
  43.  
  44. 1.4
  45. date     88.12.22.13.24.27;  author brent;  state Exp;
  46. branches ;
  47. next     1.3;
  48.  
  49. 1.3
  50. date     88.11.14.15.12.34;  author brent;  state Exp;
  51. branches ;
  52. next     1.2;
  53.  
  54. 1.2
  55. date     88.11.11.11.32.51;  author brent;  state Exp;
  56. branches ;
  57. next     1.1;
  58.  
  59. 1.1
  60. date     88.11.02.12.42.40;  author brent;  state Exp;
  61. branches ;
  62. next     ;
  63.  
  64.  
  65. desc
  66. @Main program for NFS to Sprite gateway
  67. @
  68.  
  69.  
  70. 1.11
  71. log
  72. @Add remote mount points to support the mounting
  73. of one NFS filesystem within another.
  74. @
  75. text
  76. @/*
  77.  * NFS pseudo-filesystem server.
  78.  *
  79.  * This program is for a server process that acts as a gateway between
  80.  * a Sprite pseudo-filesystem and a remote NFS server.  This allows a
  81.  * NFS filesystem to be transparenty integrated into the Sprite distributed
  82.  * filesystem.
  83.  *
  84.  * Copyright 1988 Regents of the University of California
  85.  * Permission to use, copy, modify, and distribute this
  86.  * software and its documentation for any purpose and without
  87.  * fee is hereby granted, provided that the above copyright
  88.  * notice appear in all copies.  The University of California
  89.  * makes no representations about the suitability of this
  90.  * software for any purpose.  It is provided "as is" without
  91.  * express or implied warranty.
  92.  */
  93. #ifndef lint
  94. static char rcsid[] = "$Header: /sprite/src/cmds/nfsmount/RCS/main.c,v 1.10 91/03/23 18:34:06 mottsmth Exp Locker: mottsmth $ SPRITE (Berkeley)";
  95. #endif not lint
  96.  
  97. #include "stdio.h"
  98. #include "option.h"
  99. #include "errno.h"
  100. #include "nfs.h"
  101. #include "strings.h"
  102. #include <syslog.h>
  103.  
  104. char myhostname[1024];
  105.  
  106. /*
  107.  * Command line options.
  108.  */
  109. char *prefix = "/nfs";
  110. char *host = "ginger.Berkeley.EDU";
  111. char *rfs = "/sprite";
  112. static int trace;
  113. int nfs_PdevWriteBehind = 1;
  114.  
  115. Option optionArray[] = {
  116.     {OPT_DOC, "", (Address)NIL, "nfssrv [-t] rhost:/path /prefix"},
  117.     {OPT_DOC, "", (Address)NIL, "(or use -p, -h, -r flags)"},
  118.     {OPT_STRING, "p", (Address)&prefix,
  119.         "Sprite prefix"},
  120.     {OPT_STRING, "h", (Address)&host,
  121.         "NFS host"},
  122.     {OPT_STRING, "r", (Address)&rfs,
  123.         "Remote filesystem name"},
  124.     {OPT_FALSE, "sync", (Address)&nfs_PdevWriteBehind,
  125.         "Disable write-behind"},
  126.     {OPT_TRUE, "t", (Address)&trace,
  127.         "Turn on tracing"},
  128.     {OPT_GENFUNC, "m", (Address)NfsRecordMountPointProc,
  129.         "NFS sub-mount point"},
  130. };
  131. int numOptions = sizeof(optionArray) / sizeof(Option);
  132.  
  133. struct timeval nfsTimeout = { 25, 0 };
  134.  
  135. void DoOpt();
  136.  
  137.  
  138. /*
  139.  *----------------------------------------------------------------------
  140.  *
  141.  * main --
  142.  *
  143.  *    Main program for NFS pseudo-filesystem server.  First the NFS
  144.  *    system is mounted, and then the pseudo-filesystem is established.
  145.  *    Lastly we drop into an Fs_Dispatch loop to handle pfs requests
  146.  *    comming from the Sprite kernel.
  147.  * 
  148.  * Results:
  149.  *    None.
  150.  *
  151.  * Side effects:
  152.  *    Opens the pseudo-filesystem.
  153.  *
  154.  *----------------------------------------------------------------------
  155.  */
  156.  
  157. main(argc, argv)
  158.     int argc;
  159.     char *argv[];
  160. {
  161.     NfsState *nfsPtr;
  162.     attrstat nfsAttr;
  163.     Fs_Attributes spriteAttr;
  164.     Fs_FileID rootID;
  165.  
  166.     argc = Opt_Parse(argc, argv, optionArray, numOptions, OPT_ALLOW_CLUSTERING);
  167.  
  168.     while (argc > 1) {
  169.     /*
  170.      * Look for "host:name [prefix]"
  171.      */
  172.     register char *colonPtr = index(argv[1], ':');
  173.     if (colonPtr != (char *)0) {
  174.         host = argv[1];
  175.         *colonPtr = '\0';
  176.         rfs = colonPtr + 1;
  177.         argc--;
  178.         argv++;
  179.     } else {
  180.         prefix = argv[1];
  181.         argc--;
  182.         argv++;
  183.     }
  184.     }
  185.  
  186.     gethostname(myhostname, sizeof(myhostname));
  187.  
  188.     nfsPtr = (NfsState *)malloc(sizeof(NfsState));
  189.     nfsPtr->host = host;
  190.     nfsPtr->prefix = prefix;
  191.     nfsPtr->nfsName = rfs;
  192.  
  193.     nfsPtr->mountClnt = Nfs_MountInitClient(host);
  194.     if (nfsPtr->mountClnt == (CLIENT *)NULL) {
  195.     exit(1);
  196.     }
  197.     nfsPtr->nfsClnt = Nfs_InitClient(host);
  198.     if (nfsPtr->nfsClnt == (CLIENT *)NULL) {
  199.     exit(1);
  200.     }
  201.  
  202.     nfsPtr->mountHandle = Nfs_Mount(nfsPtr->mountClnt, nfsPtr->nfsName);
  203.     if (nfsPtr->mountHandle == (nfs_fh *)NULL) {
  204.     exit(1);
  205.     }
  206.  
  207.     /*
  208.      * Test NFS access by getting the attributes of the root.  This is
  209.      * needed in order to set the rootID properly so it matches any
  210.      * future stat() calls by clients.
  211.      */
  212.     if (!NfsProbe(nfsPtr, trace, &nfsAttr)) {
  213.     Nfs_Unmount(nfsPtr->mountClnt, rfs);
  214.     exit(1);
  215.     }
  216.     NfsToSpriteAttr(&nfsAttr.attrstat_u.attributes, &spriteAttr);
  217.     rootID.serverID = spriteAttr.serverID;
  218.     rootID.type = TYPE_ROOT;
  219.     rootID.major = spriteAttr.domain;
  220.     rootID.minor = spriteAttr.fileNumber;
  221.     /*
  222.      * Set ourselves up as the server of the pseudo-file-system.  We'll
  223.      * see requests via the call-backs in nfsNameService.
  224.      */
  225.     if (trace) {
  226.     printf("RootID <%d,%d,%d,%d>\n", rootID.serverID, rootID.type,
  227.             rootID.major, rootID.minor);
  228.     }
  229.     nfsPtr->pfsToken = Pfs_Open(prefix, &rootID, &nfsNameService,
  230.     (ClientData)nfsPtr);
  231.     if (nfsPtr->pfsToken == (Pfs_Token)NULL)  {
  232.     if (trace) {
  233.             printf("%s\n", pfs_ErrorMsg);
  234.     }
  235.         syslog(LOG_ERR, "nfsmount: %s", pfs_ErrorMsg);
  236.     Nfs_Unmount(nfsPtr->mountClnt, rfs);
  237.     exit(1);
  238.     }
  239.  
  240.     if (trace) {
  241.     pdev_Trace = pfs_Trace = trace;
  242.     printf("NFS (traced): ");
  243.     } else {
  244.     printf("NFS: ");
  245.     }
  246.     printf("%s => %s:%s\n", prefix, host, rfs);
  247.  
  248.     if (!trace) {
  249.     Proc_Detach(0);
  250.     }
  251.  
  252.     while (1) {
  253.     Fs_Dispatch();
  254.     }
  255. }
  256.  
  257. /*
  258.  *----------------------------------------------------------------------
  259.  *
  260.  * BadProc --
  261.  *
  262.  *    Called by accident.
  263.  * 
  264.  * Results:
  265.  *    None.
  266.  *
  267.  * Side effects:
  268.  *    Enter the debugger.
  269.  *
  270.  *----------------------------------------------------------------------
  271.  */
  272. int
  273. BadProc()
  274. {
  275.     panic("Bad callback\n");
  276. }
  277.  
  278.  
  279. @
  280.  
  281.  
  282. 1.10
  283. log
  284. @typo
  285. @
  286. text
  287. @d19 1
  288. a19 1
  289. static char rcsid[] = "$Header: /sprite/src/cmds/nfsmount/RCS/main.c,v 1.9 91/03/23 18:30:03 mottsmth Exp Locker: mottsmth $ SPRITE (Berkeley)";
  290. d53 2
  291. @
  292.  
  293.  
  294. 1.9
  295. log
  296. @*** empty log message ***
  297. @
  298. text
  299. @d19 1
  300. a19 1
  301. static char rcsid[] = "$Header: /sprite/src/cmds/nfsmount/RCS/main.c,v 1.8 91/03/23 18:24:45 mottsmth Exp Locker: mottsmth $ SPRITE (Berkeley)";
  302. d157 1
  303. @
  304.  
  305.  
  306. 1.8
  307. log
  308. @Added message in the event that Pfs_Open fails.
  309. @
  310. text
  311. @d19 1
  312. a19 1
  313. static char rcsid[] = "$Header: /sprite/src/cmds/nfsmount/RCS/main.c,v 1.7 90/01/25 17:19:06 brent Exp $ SPRITE (Berkeley)";
  314. @
  315.  
  316.  
  317. 1.7
  318. log
  319. @Added -sync flag to disable write-behind
  320. @
  321. text
  322. @d19 1
  323. a19 1
  324. static char rcsid[] = "$Header: /a/newcmds/nfsmount/RCS/main.c,v 1.6 89/06/16 08:50:31 brent Exp Locker: douglis $ SPRITE (Berkeley)";
  325. d27 1
  326. d155 3
  327. @
  328.  
  329.  
  330. 1.6
  331. log
  332. @Fixed call to Pdev_Open so a good value of the rootID iss
  333. givento the kernel.
  334. ./
  335. @
  336. text
  337. @d19 1
  338. a19 1
  339. static char rcsid[] = "$Header: /a/newcmds/nfsmount/RCS/main.c,v 1.5 89/02/02 15:02:43 brent Exp $ SPRITE (Berkeley)";
  340. d37 1
  341. d48 2
  342. @
  343.  
  344.  
  345. 1.5
  346. log
  347. @Fixed tracing variable
  348. @
  349. text
  350. @d19 1
  351. a19 1
  352. static char rcsid[] = "$Header: /a/newcmds/nfsmount/RCS/main.c,v 1.4 88/12/22 13:24:27 brent Exp $ SPRITE (Berkeley)";
  353. d81 2
  354. d126 22
  355. a147 1
  356.     bzero((char *)&rootID, sizeof(rootID));
  357. @
  358.  
  359.  
  360. 1.4
  361. log
  362. @Added OPT_DOC help lines
  363. @
  364. text
  365. @d19 1
  366. a19 1
  367. static char rcsid[] = "$Header: /a/newcmds/nfssrv/RCS/main.c,v 1.3 88/11/14 15:12:34 brent Exp $ SPRITE (Berkeley)";
  368. d36 1
  369. d47 1
  370. a47 1
  371.     {OPT_TRUE, "t", (Address)&pdevTrace,
  372. d81 1
  373. a81 1
  374.     ClientData pfsToken;
  375. a83 1
  376.     DoOpt(argc, argv);
  377. d124 4
  378. a127 2
  379.     pfsToken = Pfs_Open(prefix, (ClientData)nfsPtr, nfsNameService);
  380.     if (pfsToken == (ClientData)NULL)  {
  381. d132 2
  382. a133 1
  383.     if (pdevTrace) {
  384. d140 1
  385. a140 1
  386.     if (!pdevTrace) {
  387. a146 21
  388. }
  389.  
  390. /*
  391.  *----------------------------------------------------------------------
  392.  *
  393.  * DoOpt --
  394.  *
  395.  *    Called from main to take action according to command line arguments.
  396.  * 
  397.  * Results:
  398.  *    None.
  399.  *
  400.  * Side effects:
  401.  *    Turns off tracing, etc.
  402.  *
  403.  *----------------------------------------------------------------------
  404.  */
  405. void DoOpt(argc, argv)
  406.     int argc;
  407.     char *argv[];
  408. {
  409. @
  410.  
  411.  
  412. 1.3
  413. log
  414. @Added call to Proc_Detach()
  415. @
  416. text
  417. @d19 1
  418. a19 1
  419. static char rcsid[] = "$Header: /a/newcmds/nfssrv/RCS/main.c,v 1.2 88/11/11 11:32:51 brent Exp $ SPRITE (Berkeley)";
  420. d38 2
  421. @
  422.  
  423.  
  424. 1.2
  425. log
  426. @Last nfstest version
  427. @
  428. text
  429. @d19 1
  430. a19 1
  431. static char rcsid[] = "$Header: /sprite/users/brent/nfstest/RCS/main.c,v 1.1 88/11/02 12:42:40 brent Exp $ SPRITE (Berkeley)";
  432. d28 2
  433. a35 2
  434. char *fileName = "users/brent";
  435. char *spriteName = "/etc/passwd";
  436. a36 5
  437. Boolean lookup        = FALSE;
  438. Boolean cat        = FALSE;
  439. Boolean writeTest    = FALSE;
  440. Boolean serveIt        = FALSE;
  441.  
  442. a43 12
  443.     {OPT_STRING, "f", (Address)&fileName,
  444.         "Name relative to remote filesystem root"},
  445.     {OPT_STRING, "s", (Address)&spriteName,
  446.         "Name of Sprite file (for -W)"},
  447.     {OPT_TRUE, "S", (Address)&serveIt,
  448.         "Service a pseudo-filesystem"},
  449.     {OPT_TRUE, "L", (Address)&lookup,
  450.         "Do lookup test"},
  451.     {OPT_TRUE, "R", (Address)&cat,
  452.         "Do read test"},
  453.     {OPT_TRUE, "W", (Address)&writeTest,
  454.         "Do write test"},
  455. d101 2
  456. a121 21
  457.  
  458.     if (!(serveIt | lookup | cat | writeTest)) {
  459.     NfsProbe(nfsPtr);
  460.     lookup = TRUE;
  461.     }
  462.     if (writeTest) {
  463.     NfsWriteTest(nfsPtr, spriteName, fileName);
  464.     }
  465.     if (lookup) {
  466.     NfsLookupTest(nfsPtr, fileName);
  467.     }
  468.     if (cat) {
  469.     NfsReadTest(nfsPtr, fileName);
  470.     }
  471.  
  472.     if (!serveIt) {
  473.     Nfs_Unmount(nfsPtr->mountClnt, rfs);
  474.     printf("\nquitting\n");
  475.     exit(1);
  476.     }
  477.  
  478. d134 4
  479. @
  480.  
  481.  
  482. 1.1
  483. log
  484. @Initial revision
  485. @
  486. text
  487. @d19 1
  488. a19 1
  489. static char rcsid[] = "$Header: fsPfs.c,v 6.0 88/10/11 15:52:49 brent Exp $ SPRITE (Berkeley)";
  490. d26 1
  491. d99 18
  492. @
  493.